'use strict';
const bcrypt = require('bcryptjs');

module.exports = app => {
  const { INTEGER, STRING, TEXT, DATE } = app.Sequelize;

  const Users = app.model.define('users', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    username: STRING(50),
    password: {
      type: STRING(64),
      set(val) {
        const salt = bcrypt.genSaltSync(10);
        const spwd = bcrypt.hashSync(val, salt);
        this.setDataValue('password', spwd);
      },
    },
    avatar: TEXT('long'),
    phone: STRING(20),
    sign: STRING(300),
    createTime: {
      type: DATE,
    },
    updateTime: {
      type: DATE,
    },
    signTime: {
      type: DATE,
    },
  });
  return Users;
};
